package com.sit.service.impl;

import com.sit.dao.adminMapper;
import com.sit.pojo.*;
import com.sit.service.adminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class adminServiceImpl implements adminService {
    @Autowired
    private adminMapper adminMapper;

    @Override
    public administrator login(String name){
        administrator result = null;
        try {
            result = adminMapper.login(name);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public int updatePwd(administrator admin){
        int result = 0;
        try {
            result = adminMapper.updatePwd(admin);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public administrator findAdminById(String id){
        administrator result = null;
        try {
            result = adminMapper.findAdminById(id);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public List<Readers> findAllReader() {
        List<Readers> readers = null;
        try {
            readers = adminMapper.findAllReader();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return readers;
    }

    @Override
    public Readers findReaderById(String id) {
        Readers reader = null;
        try {
            reader = adminMapper.findReaderById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return reader;
    }

    @Override
    public List<Readers> findReaderByName(String name){
        List<Readers> reader = null;
        try {
            reader = adminMapper.findReaderByName(name);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return reader;
    }

    public int updateReader(Readers reader){
        int result = 0;
        try {
            result = adminMapper.updateReader(reader);
        }
        catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public int deleteReader(String id) {
        int result = 0;
        try {
            result = adminMapper.deleteReader(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public List<js_card> findAllReaderCard(){
        List<js_card> js_card = null;
        try {
            js_card = adminMapper.findAllReaderCard();
        }catch (Exception e){
            e.printStackTrace();
        }
        return js_card;
    }

    @Override
    public int deleteReaderCard(String id){
        int result = 0;
        try {
            result = adminMapper.deleteReaderCard(id);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public int insertBook(books book){
        int result = 0;
        try {
            result = adminMapper.insertBook(book);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public int deleteBook(String id) {
        int result = 0;
        try {
            result = adminMapper.deleteBook(id);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public int updateBook(books book){
        int result = 0;
        try {
            result = adminMapper.updateBook(book);
        }catch(Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public books findBookById(String id) {
        books result = null;
        try {
            result = adminMapper.findBookById(id);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public List<books> findBookByName(String name) {
        List<books> result = null;
        try {
            result = adminMapper.findBookByName(name);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public List<books> findAllBook() {
        List<books> result = null;
        try {
            result = adminMapper.findAllBook();
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public int insertBookType(books_type bookType) {
        int result = 0;
        try {
            result = adminMapper.insertBookType(bookType);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public int deleteBookType(String id) {
        int result = 0;
        try {
            result = adminMapper.deleteBookType(id);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public int updateBookType(books_type book) {
        int result = 0;
        try {
            result = adminMapper.updateBookType(book);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public books_type findBookTypeById(String id) {
        books_type result = null;
        try {
            result = adminMapper.findBookTypeById(id);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public List<books_type> findAllBookType() {
        List<books_type> result = null;
        try{
            result = adminMapper.findAllBookType();
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public List<hisborrow> findAllBorrow() {
        List<hisborrow> result = null;
        try{
            result = adminMapper.findAllBorrow();
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public int deleteBorrow(hisborrow borrow) {
        int result = 0;
        try{
            result = adminMapper.deleteBorrow(borrow);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public List<borrow> NowBorrow() {
        List<borrow> result = null;
        try {
            result = adminMapper.NowBorrow();
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public List<punish> findAllPunish() {
        List<punish> result = null;
        try{
            result = adminMapper.findAllPunish();
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public List<Readers> findReaderByInput(Readers reader){
        List<Readers> result = null;
        try{
            result = adminMapper.findReaderByInput(reader);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public List<books> findBookByInput(books book){
        List<books> result = null;
        try{
            result = adminMapper.findBookByInput(book);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public List<books_type> findBookTypeByInput(books_type bookType){
        List<books_type> result = null;
        try{
            result = adminMapper.findBookTypeByInput(bookType);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }
}
